<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片切换</title>
    <link rel="stylesheet" href="css/slider.css">
</head>
<body>
    <div id="vm">
        <div class="layer">
            <img :src="img_src" alt="" class="img">
            <ul>
                <li v-for="(el,idx) in img_num" :class="{'active':idx == current_id}" @click="change(idx)">{{el}}</li>
            </ul>
        </div>
    </div>
    <script src="js/vue.js"></script>
    <script>
        var vm = new Vue({
            el:"#vm",
            data:{
                img_list:["img/l1.jpg","img/l2.webp","img/l3.webp","img/l4.webp","img/l5.webp"],
                img_src:'',
                img_num:[],
                current_id:0
            },
            mounted(){
                this.load();
            },
            methods:{
                load(){
                    var len = this.img_list.length;
                    if(len > 0){
                        for(var i=1;i<=len;i++){
                            this.img_num.push(i);
                        }
                        this.img_src = this.img_list[0];
                    }
                },
                change(num){
                    this.current_id = num;
                    this.img_src = this.img_list[num];
                }
            }
        })
    </script>
</body>
</html>